package cn.heima.cn;

import java.util.*;

public class Demo4 {
    public static void main(String[] args) {
        Map<Integer,String> map = new TreeMap<>();
        map.put(11,"aa");
        map.put(44,"dd");
        map.put(66,"ff");
        map.put(22,"bb");
        map.put(55,"ee");
        map.put(33,"cc");

        Set<Map.Entry<Integer, String>> entries = map.entrySet();
        for (Map.Entry<Integer, String> entry : entries) {
            System.out.println(entry.getKey()+" -- " + entry.getValue());
        }

        System.out.println("---------");

        Map<String,Integer> map2 = new TreeMap<>();
        map2.put("adsgfaa",11);
        map2.put("adfhgsdf",44);
        map2.put("egrndhrexfg",66);
        map2.put("drgjhndresd",22);
        map2.put("awsega",55);
        map2.put("caefraec",33);
        Set<Map.Entry<String, Integer>> entries2 = map2.entrySet();

        Set<Map.Entry<String, Integer>> set  =new TreeSet<>(new Comparator<Map.Entry<String, Integer>>() {
            @Override
            public int compare(Map.Entry<String, Integer> o1, Map.Entry<String, Integer> o2) {
                return  o1.getValue() - o2.getValue();
            }
        });
        set.addAll(entries2);
        for (Map.Entry<String, Integer> entry : set) {
            System.out.println(entry.getKey()+" -- " + entry.getValue());
        }
    }
}
